import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;


public class VendingMachineItemTest {

	//create some static variables for the vending machine and the item
	private static VendingMachineItem myItem;
	private static VendingMachine myMachine;
	
	//set up a generic vending machine
	@BeforeClass
	public static void setUpBeforeClass() throws Exception 
	{
		myMachine = new VendingMachine();
			
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception 
	{
		
		
	}

	//test the constructor
	//creates a new machine and adds an item to the vending machine
	//the item is then retrieved from the vending machine and checked against the original item
	@SuppressWarnings("static-access")
	@Test
	public void testVendingMachineItem() 
	{
		myMachine = new VendingMachine();
		VendingMachineItem myItem = new VendingMachineItem("Baby Ruth",1.00);
		myMachine.addItem(myItem, myMachine.D_CODE);
		VendingMachineItem testItem = myMachine.getItem(myMachine.D_CODE);
		assertEquals(myItem,testItem);
	}
	
	
	//can we add a null item name with no price
	//creates a new machine and adds an item with a null name to the vending machine
	//the item is then retrieved from the vending machine and checked against the original item
	//this test should pass later we test the same setup and we can make a purchase with a null name and 0 price
	@SuppressWarnings("static-access")
	@Test
	public void testVoidItem()
	{
		myMachine = new VendingMachine();
		VendingMachineItem myItem = new VendingMachineItem(null,0);
		myMachine.addItem(myItem, myMachine.D_CODE);
		VendingMachineItem testItem = myMachine.getItem(myMachine.D_CODE);
		assertEquals(myItem,testItem);
		//this should pass this way but there is a bug in the code
		assertFalse(myMachine.makePurchase(myMachine.D_CODE));
		//assertTrue(myMachine.makePurchase(myMachine.D_CODE));
	
	}
	
	//test to get the name from the item
	//create a new vending machine item with a legit name
	//add the item to a vending machine and see if we get the same name out of the machine
	@SuppressWarnings("static-access")
	@Test
	public void testGetName() 
	{
		myItem = new VendingMachineItem("Milky Way",0);
		myMachine.addItem(myItem, myMachine.A_CODE);
		VendingMachineItem newItem = myMachine.getItem(myMachine.A_CODE);
		assertEquals("Milky Way",newItem.getName());
	}
	
	//test for empty string name - this should fail with an empty string name
	//adds a new item with an empty string as the name and 0 price
	//the item is added to a vending machine and is retrieved from the machine and checked with the original item
	@SuppressWarnings("static-access")
	@Test
	public void testEmptyStringName()
	{
		myItem = new VendingMachineItem("",0);
		myMachine.addItem(myItem, myMachine.D_CODE);
		VendingMachineItem newItem = myMachine.getItem(myMachine.D_CODE);
		assertEquals("",newItem.getName());
	}
	
	//test to get the price from the item
	//create an item with legit name and price
	//add the item to the vending machine
	//get the item from the machine and test to verify the price is the same
	@SuppressWarnings("static-access")
	@Test
	public void testGetPrice() 
	{
		myItem = new VendingMachineItem("Milky Way",50);
		myMachine.addItem(myItem, myMachine.B_CODE);
		VendingMachineItem newItem = myMachine.getItem(myMachine.B_CODE);
		assertEquals(50,newItem.getPrice(),.01);
	}
	
	//test the item code - this should fail as the code should be enforced with an enum type
	//create a vending machine and create an item with a code of "A"
	//add the item to the machine and the get the item from the machine with the code "A_CODE";
	//compare the original item with the one put in the machine and somewhere along that line there
	//should be something that forces referential types
	@SuppressWarnings("static-access")
	@Test
	public void testItemCode()
	{
		VendingMachine myMachine = new VendingMachine();
		VendingMachineItem myItem = new VendingMachineItem("A",0);
		myMachine.addItem(myItem, "A");
		VendingMachineItem newItem = myMachine.getItem(myMachine.A_CODE);
		//this test should fail as the two are not the same - the item code should enforce types with an enum
		assertFalse(myItem.equals(newItem));
		//assertTrue(myItem.equals(newItem));
	}
	
	
	//test to enter a negative number in the item - throws an error
	@Test(expected = VendingMachineException.class)
	public void testGetPriceNegNumber()
	{
		myItem = new VendingMachineItem("Milky Way",-50);
		
	}

}
